package com.haredot.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.haredot.validation.Insert;
import com.haredot.validation.Update;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.Range;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.time.LocalDateTime;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@TableName(value = "tb_svip_config")
public class SvipConfig {
    @TableId(value = "id", type = IdType.ASSIGN_ID)
    @JsonSerialize(using = ToStringSerializer.class)
    @NotNull(message = "ID不允许为空", groups = Update.class)
    private Long id;

    /**
     * 套餐名
     */
    @TableField(value = "name")
    @NotEmpty(message = "套餐名不允许为空", groups = {Update.class, Insert.class})
    @Length(max = 50, message = "套餐名长度超出50个字符", groups = {Update.class, Insert.class})
    private String name;

    /**
     * 价格
     */
    @TableField(value = "price")
    @NotEmpty(message = "套餐价格不允许为空", groups = {Update.class, Insert.class})
    @Pattern(regexp = "^\\d+$", message = "套餐价格必须是一个整数", groups = {Update.class, Insert.class})
    private String price;

    /**
     * 过期时间，单位天
     */
    @TableField(value = "exp")
    @NotNull(message = "套餐过期时间不允许为空", groups = {Update.class, Insert.class})
    private Integer exp;

    /**
     * 积分数量
     */
    @TableField(value = "score")
    @NotNull(message = "赠送积分不允许为空", groups = {Update.class, Insert.class})
    @Range(min = 0, max = Integer.MAX_VALUE, message = "赠送积分数量不符合要求", groups = {Update.class, Insert.class})
    private Integer score;

    /**
     * 状态
     */
    @TableField(value = "state")
    @NotNull(message = "状态不允许为空", groups = {Update.class, Insert.class})
    private Boolean state;

    /**
     * 录入时间
     */
    @TableField(value = "create_time", fill = FieldFill.INSERT)
    private LocalDateTime createTime;

    /**
     * 修改时间
     */
    @TableField(value = "update_time", fill = FieldFill.UPDATE)
    private LocalDateTime updateTime;

    /**
     * 删除标记
     */
    @TableField(value = "del")
    private Boolean del;
}